<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>

<script type="text/javascript">

var test = "setTimeout";
var zushe = true;

var start = new Date().getTime(); 
var count = 0; 
var intervalTime = 1000; 

if (zushe) {
	setInterval(function(){ 
		var j = 0; 
		while(j++ < 100000000); 
	}, 0); 
}

// 测试 setTimeout 的实际延迟
if (test === "setTimeout") {
	setTimeout(function(){ 
	     count++; 
	     // 200 上下
	     console.log("setTimeout", new Date().getTime() - (start + count * 1000)); 
	},1000); 
} else {
	var flag = true;
	(function countDownStart(){
		console.log(1111)
		var _now = Date.now();
		var _left = _now - start;
	    if ((_left) >= (count + 1) * intervalTime) {
	    	// 防止是延迟了多次区间，切换浏览器的tab时，requestAnimationFrame 不会被执行
	    	count = parseInt((_left / intervalTime),10);
			var offset = _now - (start + count * intervalTime);
	     	// 100 上下
			console.log("requestAnimationFrame", offset);
			flag = false;
		}
		flag && window.requestAnimationFrame(countDownStart);    
	})()
}

</script>
</body>
</html>